<template>
	<view class="zb-cell">
		<view class="zb-cell-left-box">
			<text class="zb-cell-left-title" v-if="type == 0">{{typeName}}</text>
			<text :style="statusStyle">{{statusName}}</text>
			<text class="zb-cell-left-time">{{time}}</text>
		</view>
		<view class="zb-cell-right-box">
			<text>{{money}}</text>
			<image class="zb-cell-right-icon" src="/static/right_gray_icon.png" mode="aspectFit"></image>
		</view>
		<view class="zb-cell-line"></view>
	</view>
</template>

<script setup>
	import { computed } from 'vue'
	
	const showType = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return false
		}
		if(uni.$u.test.isEmpty(props.params.settleOrderNo)){
			return false
		}
		return true
	})
	
	const statusStyle = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return {color:'#FF0203'}
		}
		if(props.type == 0){
			//交易订单
			if(props.params.txnStatus == '1'){
				return {color:'#008000'}
			}
			else if(props.params.txnStatus == '4'){
				return {color:'#1890FF'}
			}
			else{
				return {color:'#FF0203'}
			}
		}
		else{
			//结算订单
			if(props.params.settleStatus == '1'){
				return {color:'#1890FF'}
			}
			else if(props.params.settleStatus == '2'){
				return {color:'#008000'}
			}
			else{
				return {color:'#FF0203'}
			}
		}
	})
	//交易类型
	const typeName = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return ''
		}
		if(props.params.txnType == '00'){
			return '刷卡'
		}
		else if(props.params.txnType == '01'){
			return '扫码'
		}
		return ''
	})
	//状态
	const statusName = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return ''
		}
		if(props.type == 0){
			//交易订单
			if(props.params.txnStatus == '1'){
				return '交易成功'
			}
			else if(props.params.txnStatus == '4'){
				return '处理中'
			}
			else{
				return '交易失败'
			}
		}
		else{
			//结算订单
			if(props.params.settleStatus == '1'){
				return '结算中'
			}
			else if(props.params.settleStatus == '2'){
				return '已结算'
			}
			else{
				return '结算失败'
			}
		}
	})
	//时间
	const time = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return ''
		}
		if(props.type == 0){
			//交易订单
			return props.params.txnTime
		}
		else{
			//结算订单
			if(!uni.$u.test.isEmpty(props.params.settleDate)){
				return props.params.settleDate.slice(0,10)
			}
			return props.params.settleDate
		}
	})
	//金额
	const money = computed(()=>{
		if(uni.$u.test.isEmpty(props.params)){
			return '¥0'
		}
		if(props.type == 0){
			//交易订单
			return `¥${props.params.txnAmount}`
		}
		else{
			//结算订单
			return `¥${props.params.settleTxnAmt}`
		}
	})
	const props = defineProps({
		type:{ //0：交易订单 1：结算订单
			type:Number,
			default:0
		},
		params:Object
		
	})
</script>

<style lang="scss" scoped>
	.zb-cell{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 30rpx;
		position: relative;
		background-color: white;
		.zb-cell-left-box{
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 24rpx;
			color: $xh-subtitle-color;
			.zb-cell-left-title{
				color: $xh-title-color;
				font-size: 28rpx;
				margin-bottom: 10rpx;
			}
			.zb-cell-left-time{
				color: $xh-subtitle-color;
				margin-top: 10rpx;
			}
		}
		.zb-cell-right-box{
			display: flex;
			align-items: center;
			flex-shrink: 0;
			color: $xh-theme-color;
			font-size: 28rpx;
			font-weight: 500;
			margin-left: 20rpx;
			.zb-cell-right-icon{
				width: 24rpx;
				height: 24rpx;
				margin-left: 10rpx;
			}
		}
		.zb-cell-line{
			position: absolute;
			left: 30rpx;
			right: 30rpx;
			bottom: 0;
			height: 1px;
			transform: translateY(0.5);
			background-color: $xh-line-color;
		}
	}
</style>